package com.coolzeng.controller;

import com.alibaba.fastjson.JSON;
import com.coolzeng.entity.JsonResult;
import com.coolzeng.entity.Post;
import com.coolzeng.service.PostService;
import com.coolzeng.service.ReplyService;
import com.sun.tools.internal.ws.processor.model.Request;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpRequest;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * Created by Administrator on 2017/6/9.
 */
@Controller
@RequestMapping("post")
public class PostController {
    @Autowired
    private PostService postService;
    @Autowired
    private ReplyService replyService;

    @ResponseBody
    @RequestMapping("/allPost")
    public JsonResult post(){
        List<Post> posts=postService.selectAllPost();
        JsonResult jsonResult=new JsonResult(posts,"this is message",true);
        return jsonResult;
    }

    @ResponseBody
    @RequestMapping("/getTableCount")
    public int postcount(){
        int tableCount= postService.getPostCount();
        return tableCount;
    }

    @RequestMapping(value = "/addPost",produces = "application/json;charset=utf-8")
    @ResponseBody
    public void addPost(@RequestBody Post updpost){
        System.out.println(updpost.getPostcontent()+updpost.getPosttitle());
        String postImgUrl="";
        int  postReplyNum=0;
        Post post=new Post();

        post.setPostuserid(4);
        post.setPosttitle(updpost.getPosttitle());
        post.setPostcontent(updpost.getPostcontent());
        post.setPostimgurl(postImgUrl);
        post.setPostreplynum(postReplyNum);

        postService.instrt(post);
    }



}
